package revolucion.window;

import revolucion.database.Database;
import revolucion.classes.Log;

import java.awt.Dimension;

import javax.swing.ImageIcon;
import javax.swing.table.DefaultTableModel;

public class Window_Logs extends javax.swing.JFrame {
  public Window_Logs() {
    super(".:: Logs");

    initComponents();

    setIconImage(new ImageIcon(getClass().getResource("/revolucion/resources/admin.gif")).getImage());

    DefaultTableModel md = Database.getLogsTableModel();
    tab_logs.setModel( md );

    Dimension dim = this.getToolkit().getScreenSize();
    int x = (int) (dim.getWidth()  - this.getSize().getWidth() ) / 2;
    int y = (int) (dim.getHeight() - this.getSize().getHeight()) / 2;
    this.setLocation(x,y);
  }

    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jToolBar1 = new javax.swing.JToolBar();
    jLabel1 = new javax.swing.JLabel();
    lbl_totalLogs = new javax.swing.JLabel();
    jToolBar2 = new javax.swing.JToolBar();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    tab_logs = new javax.swing.JTable();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    jToolBar1.setFloatable(false);
    jToolBar1.setRollover(true);
    jToolBar1.setName("jToolBar1"); // NOI18N

    jLabel1.setText("Total de logs:");
    jLabel1.setName("jLabel1"); // NOI18N
    jToolBar1.add(jLabel1);

    lbl_totalLogs.setText("xxx");
    lbl_totalLogs.setName("lbl_totalLogs"); // NOI18N
    jToolBar1.add(lbl_totalLogs);

    jToolBar2.setFloatable(false);
    jToolBar2.setRollover(true);
    jToolBar2.setName("jToolBar2"); // NOI18N

    jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/limpar_logs.gif"))); // NOI18N
    jButton1.setToolTipText("Limpar arquivo de log");
    jButton1.setFocusable(false);
    jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton1.setName("jButton1"); // NOI18N
    jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    jToolBar2.add(jButton1);

    jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/revolucion/resources/search_log.gif"))); // NOI18N
    jButton2.setFocusable(false);
    jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton2.setName("jButton2"); // NOI18N
    jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar2.add(jButton2);

    jScrollPane1.setName("jScrollPane1"); // NOI18N

    tab_logs.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null},
        {null, null, null, null}
      },
      new String [] {
        "Title 1", "Title 2", "Title 3", "Title 4"
      }
    ));
    tab_logs.setName("tab_logs"); // NOI18N
    jScrollPane1.setViewportView(tab_logs);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 575, Short.MAX_VALUE)
      .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 575, Short.MAX_VALUE)
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 575, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      Log.clear();
      DefaultTableModel md = Database.getLogsTableModel();
      tab_logs.setModel( md );
    }//GEN-LAST:event_jButton1ActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JToolBar jToolBar1;
  private javax.swing.JToolBar jToolBar2;
  public javax.swing.JLabel lbl_totalLogs;
  public javax.swing.JTable tab_logs;
  // End of variables declaration//GEN-END:variables
}
